package net.zdreamer.shunyi.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;


import java.util.ArrayList;
import java.util.List;

import net.zdreamer.shunyi.R;
import net.zdreamer.shunyi.adapter.HomepageViewPagerAdapter;
import net.zdreamer.shunyi.myview.CustomViewPager;

public class GuideActivity extends Activity implements OnPageChangeListener ,View.OnClickListener {
    int index = 0;
    List<View> advPics = new ArrayList<View>();
    List<ImageView> list_vs;// 点
    private LinearLayout DotsOnViewPager;
    private CustomViewPager customViewPager;
    private HomepageViewPagerAdapter viewPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guid);
        initViewPager();
        customViewPager.setOnPageChangeListener(this);
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        //customViewPager.setCurrentItem(position);
        initDots(list_vs.size(), position, true);

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
    /*
        * 初始化ViewPager
        */
    private void initViewPager() {

        list_vs = new ArrayList<ImageView>();
        customViewPager = (CustomViewPager)findViewById(R.id.viewpager_homepage);
        DotsOnViewPager = (LinearLayout)findViewById(R.id.assss);
        viewPagerAdapter = new HomepageViewPagerAdapter(GuideActivity.this);
        customViewPager.setAdapter(viewPagerAdapter);
        viewPagerAdapter.notifyDataSetChanged();
    //    ViewControlor.setSize(getActivity(), customViewPager, 12, 5, true);
        int count = viewPagerAdapter.getCount();

        initDots(count, 0, false);

    }
    /*
    * 初始化Docs
    */
    private void initDots(int cc, int cur, boolean f) {
        for (int j = 0; j < cc; j++) {
            if (f) {
                if (j == cur) {
                    list_vs.get(j).setImageResource(R.drawable.page_now);
                } else {
                    list_vs.get(j).setImageResource(R.drawable.page);
                }
            } else {
                ImageView v = new ImageView(GuideActivity.this);
                v.setPadding(3, 0, 3, 0);
                if (j == 0) {
                    v.setImageResource(R.drawable.page_now);
                } else {
                    v.setImageResource(R.drawable.page);
                }
                list_vs.add(v);
                DotsOnViewPager.addView(v);
            }
        }
    }

    @Override
    public void onClick(View v) {

    }
}
